completing the square to find max min